import { message } from "antd";
import axios from "axios";
import router from 'umi/router';

const server=axios.create({
    baseURL:"http://123.57.143.201:8888/api/private/v1/"
})

server.interceptors.request.use(config=>{
    let token=sessionStorage.getItem("token")
    if (token){
        config.headers['Authorization']=token
    }else{
    }
    return config
})
server.interceptors.response.use(response=>{
    console.log(response);
    let msg=response.data.meta.msg
    // let token=response.data.data.token
    // console.log(token);
    // if (token){
    //     sessionStorage.setItem("token",token)
    // }
    if (msg==='token无效'){
        message.warn(msg)
        router.push('/login')
    }else{
        
        message.success(msg)
    }
    return response.data
})
export default server